package com.naire.modul.function.dao.impl;

import java.util.ArrayList;
import java.util.List;

import net.common.dao.GeneralDaoImpl;
import net.common.service.PageBean;
import net.common.util.BeanUtils;
import com.naire.modul.function.dao.FunctionDao;
import com.naire.modul.function.pojo.Function;
import com.naire.modul.function.vo.FunctionVo;

public class FunctionDaoImpl extends GeneralDaoImpl implements FunctionDao {

	@SuppressWarnings("unchecked")
	@Override
	public List<FunctionVo> search(PageBean pageBean) throws Exception {
		StringBuilder hql = new StringBuilder("from Function order by function_num");
		List<FunctionVo> d = new ArrayList<FunctionVo>();
		List<Function> l = hibernateHandler.query(hql, pageBean);
		for(Function bean : l) {
			FunctionVo dv = new FunctionVo();
			BeanUtils.copyProperties(bean, dv);
			d.add(dv);
		}
		return d;
	}

	@Override
	public void insert(FunctionVo bean) throws Exception {
		Function pojo = new Function();
		BeanUtils.copyProperties(bean, pojo);
		hibernateHandler.insert(pojo);
	}

	@Override
	public void update(FunctionVo bean) throws Exception {
		Function pojo = (Function)hibernateHandler.find(Function.class, bean.getFunction_id());
		BeanUtils.copyProperties(bean, pojo);
		hibernateHandler.update(pojo);
	}

	@Override
	public void updateFlag(FunctionVo bean) throws Exception {
		update(bean);
	}

	@Override
	public FunctionVo find(Integer id) throws Exception {
		Function pojo = (Function)hibernateHandler.find(Function.class, id);
		FunctionVo bean = new FunctionVo();
		BeanUtils.copyProperties(pojo, bean);
		return bean;
	}
}
